<?php

  abstract class ValidatorHelper implements IValidatorHelper {

    /**
     * Validates a structured communication like "001/1234/98765".
     * @param ValidationException $ve The exception to update.
     * @param IString $vcs The communication
     * @link http://be2.php.net/manual/en/function.preg-match.php
     */
    public static function validateVcs(ValidationException &$ve, IString $vcs) {
      if (preg_match("#^[0-9]{3}/[0-9]{4}/[0-9]{5}$#", $vcs->toString()) == 0) {
        $ve->addErrorMessage(self::VCS, "The vcs is not in a correct format.");
      }
    }

    /**
     * Validates an amount like 10 or 10.10.
     * @param ValidationException $ve The exception to update.
     * @param IInteger $amount The amount.
     * @link http://be2.php.net/manual/en/function.preg-match.php
     */
    public static function validateAmount(ValidationException &$ve, $amount) {
      if (preg_match("#^[0-9]{1,}\.?[0-9]{0,}$#", $amount) == 0) {
        $ve->addErrorMessage(self::AMOUNT, "The amount is not in a correct format. Use dot (.) instead of comma (,).");
      }
    }

    /**
     * Validates a dossier number.
     * @param ValidationException $ve The exception to update.
     * @param IString $dossier The dossier.
     * @link http://be2.php.net/manual/en/function.preg-match.php
     */
    public static function validateDossierNumber(ValidationException &$ve, IString $dossier) {
      if (preg_match("#^[0-9]{14}$#", $dossier->toString()) == 0) {
        $ve->addErrorMessage(self::DOSSIER, "The dossier number is not in a correct format.");
      }
    }

    /**
     * Validates a phone number.
     * @param ValidationException $ve The exception to update.
     * @param IString $phone The phone.
     * @link http://be2.php.net/manual/en/function.preg-match.php
     */
    public static function validatePhoneNumber(ValidationException &$ve, IString $phone) {
      if (preg_match("#^[0-9]{9,10}$#", $phone->replace(new String("+32"), new String("0"))->toString()) == 0) {
        $ve->addErrorMessage(self::PHONE, "The phone number is not in a correct format.");
      }
    }

    /**
     * Validates a belgian phone number.
     * @param ValidationException $ve The exception to update.
     * @param IString $phone The phone.
     * @link http://be2.php.net/manual/en/function.preg-match.php
     */
    public static function validateLuxGsmNumber(ValidationException &$ve, IString $gsm) {
      if (preg_match("#^\+352((79|2679)[0-9]{4}|4[0-9]{5})$#", $gsm->toString()) == 0) {
        $ve->addErrorMessage(self::PHONE, "The phone number is not in a correct format.");
      }
    }

    /**
     * Validates a luxemburg phone number.
     * @param ValidationException $ve The exception to update.
     * @param IString $phone The phone.
     * @link http://be2.php.net/manual/en/function.preg-match.php
     */
    public static function validateBeGsmNumber(ValidationException &$ve, IString $gsm) {
      if (preg_match("#^\+324[0-9]{8}$#", $gsm->toString()) == 0) {
        $ve->addErrorMessage(self::PHONE, "The phone number is not in a correct format.");
      }
    }

    /**
     * Validates an email address.
     * @param ValidationException $ve The exception to update.
     * @param IString $email The email.
     * @link http://be2.php.net/manual/en/function.preg-match.php
     */
    public static function validateEmail(ValidationException &$ve, IString $email) {
      if (preg_match("#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$#", $email->toString()) == 0) {
        $ve->addErrorMessage(self::EMAIL, "The email is not correct.");
      }
    }

    /**
     * Validates a date like DD/MM/YYYY, MM/DD/YYYY, DD/MM/YY or MM/DD/YY.
     * @param ValidationException $ve The exception to update.
     * @param IString $date The date.
     * @link http://be2.php.net/manual/en/function.preg-match.php
     */
    public static function validateDate(ValidationException &$ve, IString $date) {
      if (preg_match("#^((0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])|(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01]))[- /.](19|20)?\d\d$#", $date->toString()) == 0) {
        $ve->addErrorMessage(self::DATE, "The date is not in a correct format.");
      }
    }

    /**
     * Validates an iban account number.
     * @param ValidationException $ve The exception to update.
     * @param IString $iban The iban account number.
     */
    public static function validateIban(ValidationException &$ve, IString $iban) {
      if (preg_match("#^[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}$#", $iban->toString()) == 0) {
        $ve->addErrorMessage(self::IBAN, "The iban account is not in a correct format.");
      }
    }

    /**
     * Vallidates a bic number.
     * @param ValidationException $ve The exception to update.
     * @param IString $bic The bic.
     */
    public static function validateBic(ValidationException &$ve, IString $bic) {
      if (preg_match("#^[a-zA-Z]{6}[a-zA-Z0-9]{2,5}$#", $bic->toString()) == 0) {
        $ve->addErrorMessage(self::BIC, "The bic is not in a correct format.");
      }
    }

  }

?>
